function Table(obj){
    if(typeof obj.el === 'string'){
        this.el = document.querySelector(obj.el)
    }else{
        this.el  = obj.el
    }
    this.columns = obj.columns
    this.data = obj.data
    this.init()
}
// 数据调整
// Table.prototype.dataChange = function(data){
//     let newData = data.map((item)=>{
//         return Object.defineProperty(item,'clear',{value:'<button>删除</button>'}) 
//     })
//     newData = newData.map((item)=>{
//         if(item.sex === 1){
//             item.sex = '男'
//         }else if(item.sex === 0){
//             item.sex = '女'
//         }
//         return item
//     })
//     return newData
// }
Table.prototype.init = function(){
    let table = document.createElement('table')
    let head = this.head()
    let body = this.body()
    table.border = '1px'
    table.innerHTML =  `
        <thead>${head}</thead>
        <tbody>${body}</tbody>
    `
    this.el.appendChild(table)
    this.remove()
}
Table.prototype.head = function(){
   return this.columns.map((item)=>{
        return `<th>${item.title}</th>`
    }).join('')
}
Table.prototype.body = function(){
   return this.data.map((obj)=>{
        let td = this.columns.map((item)=>{
            let content = item.render ? item.render(obj) : obj[item.dataIndex]
            return `<td>${content}</td>`
        }).join('')
        return `<tr>${td}</tr>`
    }).join('')
}
Table.prototype.remove = function(){
    this.delbtns = [...document.querySelectorAll('.delBtn')]
    this.delbtns.forEach((btn)=>{
        btn.addEventListener('click',()=>{
            let index = this.delbtns.indexOf(btn)
            this.data.splice(index,1)
            let tbody = document.querySelector('tbody')
            tbody.innerHTML = this.body()
            this.remove()
        })
    })
}